package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: FileController
 * @Author: WDD
 * @CreateTime: 2022-12-01  23:59
 * @Description:
 */
@Api(tags = "文件管理")
@Slf4j
@RestController
@RequestMapping("/admin/product/")
public class FileController {

    @Autowired
    FileService fileService;

    @ApiOperation("品牌logo上传")
    @PostMapping("fileUpload")
    public Result fileUpload(@RequestPart("file") MultipartFile file) throws Exception {
        log.info("文件上传：文件名：{}，文件大小：{}，文件类型：{}",file.getOriginalFilename(),file.getSize(),file.getContentType());
        String path = fileService.upload(file);
        return Result.ok(path);
    }
}
